package com.open.capacity.service.impl;

import com.open.capacity.dao.LoginDao;
import com.open.capacity.model.LoginModel;
import com.open.capacity.model.UserModel;
import com.open.capacity.service.LoginService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @author: y_022
 * @date: 11:37-2021/6/26
 * @description:
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginDao loginDao;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public UserModel login(LoginModel loginModel) {
        UserModel userModel = loginDao.login(loginModel);
        return userModel;
    }

    @Override
    public UserModel findUserByPhones(String phones) {
      return   loginDao.findUserByPhones(phones);

    }

    @Override
    public UserModel findUserByEmails(String Emails) {
        return  loginDao.findUserByEmails(Emails);
    }

    @Override
    public void register(UserModel userModel) {
        userModel.setPasswd(DigestUtils.md5DigestAsHex(userModel.getPasswd().getBytes()));
        loginDao.register(userModel);
        rabbitTemplate.convertAndSend("mailTopicExchange","mail.#",userModel.getEmails()); //消息交换机向符合routingKey的消息队列发送消息

    }
}
